package com.china08.yxyapi.api.manage.tec.teaching.lecture.res;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.res.YxyResBook;
import com.china08.yxyapi.entity.db.res.YxyResBookContents;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.YxyResBookContentsRepository;
import com.china08.yxyapi.repository.db.YxyResBookRepository;

/**
 * 
 * 备授课-上传资源-
 *
 */
@CrossOrigin
@RestController
public class LectureSrhUpLoadCatalogController extends YxyApiBaseController {

    @Autowired
    private YxyResBookContentsRepository yxyResBookContentsRepository;

    @Autowired
    private YxyResBookRepository yxyResBookRepository;

    @ResponseBody
    @RequestMapping(value = "/api_yw/manage/tec/teaching/lecture/res/upload/catalog/sch", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel find(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel) {

        Assert.notNull(StringUtils.defaultIfBlank(reqModel.bookContentsId, null), "目录ID为空");
        YxyResBookContents resBookContents = yxyResBookContentsRepository.findById(reqModel.bookContentsId);

        YxyResBook yxyResBook = yxyResBookRepository.findById(resBookContents.getBookId());
        RespModel model = new RespModel();
        model.bookId = yxyResBook.getId();
        model.bookName = resBookContents.getName();
        model.phaseId = yxyResBook.getPhaseId();
        model.phaseName = yxyResBook.getPhaseName();
        model.semersterId = yxyResBook.getSemersterId();
        model.semersterName = yxyResBook.getSemersterName();
        model.subjectId = yxyResBook.getSubjectId();
        model.subjectName = yxyResBook.getSubjectName();
        model.versionId = yxyResBook.getVersionId();
        model.versionName = yxyResBook.getVersionName();
        return model;
    }

    protected static class ReqModel extends YxyApiReqModel {

        public String bookContentsId;
    }

    protected static class RespModel extends YxyApiRespModel {

        public String subjectId;

        public String subjectName;

        public String versionId;

        public String versionName;

        // 学期
        public String semersterId;

        public String semersterName;

        // 学段
        public String phaseId;

        public String phaseName;

        public String bookId;

        public String bookName;

    }

}
